import React, { Component } from 'react';
import { connect } from 'react-redux';

class App extends Component {

    constructor(props) {
        super(props);
        console.log(props);
    }
    
    
  componentDidMount() {
    console.log("componentDidMount");
    console.log(this.state);
    this.setState({
        data:[{product: "bread 700g", quantity: 2, unitCost: 90}]
    })
  } 
  componentWillMount(){
    console.log("componentWillMount");
    console.log(this.props);
    this.setState({
        data:this.props.tiger.shoppingCart.cart
    })
    
  }
  render() {
    return (
      <div className="App">
       {this.state.data.map((number) => <li key={number.product.toString()}>{number.product}-{number.quantity}-{number.unitCost}</li>)}
      </div>
    );
  }
}
//需要渲染什么数据
function mapStateToProps(state) {
  return {
    tiger: state,
  }
}


export default App = connect(mapStateToProps)(App)

